Repository navigation
chore(spanner): validate positional parameter count in StatementFactory.withUnnamedParameters - #15072
Open
sakthivelmanii wants to merge 1 commit into
Open
sakthivelmanii wants to merge 1 commit into
sakthivelmanii wants to merge 1 commit into
Conversation
…ry.withUnnamedParameters ## Problem - `Statement.StatementFactory.withUnnamedParameters(String, Object...)` did not validate that the number of provided parameter values matched the number of positional `?` placeholders in the SQL string, allowing extra values to be silently ignored or missing values to fail only after a server round-trip, and returned a mutable parameter map. - Positional `?` placeholder and comment scanning could miscount placeholders across PostgreSQL `E'...'` / `e'...'` escape strings, dollar-quote tag and identifier `$` boundaries, nested block comments with adjacent delimiters (`/*/*/` and `*/*`), unterminated block comments, and bare `\r` line endings. ## Solution - Validate non-null `Dialect`, `sql`, and `values` arguments in `Statement.StatementFactory`, check that the parsed `?` placeholder count matches `values.length` before converting parameter values (throwing `SpannerException` with `ErrorCode.INVALID_ARGUMENT` on any mismatch, including when values are passed without `?` placeholders), and return an unmodifiable parameter map. - Align client-side SQL lexical scanning for GoogleSQL and PostgreSQL across PostgreSQL escape string constants, dollar-quote tag and identifier boundaries, nested and unterminated block comments, and bare `\r` line endings in comments and single-line literals.
Contributor
There was a problem hiding this comment.
Code Review
This pull request enhances SQL parsing and parameter validation in the Cloud Spanner Java client. It introduces strict validation in Statement.withUnnamedParameters to ensure the number of positional parameters matches the provided values, adds support for PostgreSQL escape string constants (E'...'), and improves the handling of carriage returns (\r), dollar-quoted string tags, and nested multi-line comments. Comprehensive unit tests have been added to verify these changes. No review comments were provided, so there is no additional feedback to address.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Statement.StatementFactory.withUnnamedParameters(String, Object...)did not validate that the number of provided parameter values matched the number of positional?placeholders in the SQL string, allowing extra values to be silently ignored or missing values to fail only after a server round-trip, and returned a mutable parameter map.?placeholder and comment scanning could miscount placeholders across PostgreSQLE'...'/e'...'escape strings, dollar-quote tag and identifier$boundaries, nested block comments with adjacent delimiters (/*/*/and*/*), unterminated block comments, and bare\rline endings.Solution
Dialect,sql, andvaluesarguments inStatement.StatementFactory, check that the parsed?placeholder count matchesvalues.lengthbefore converting parameter values (throwingSpannerExceptionwithErrorCode.INVALID_ARGUMENTon any mismatch, including when values are passed without?placeholders), and return an unmodifiable parameter map.\rline endings in comments and single-line literals.